import $http from '../../http-request/request.js';
// pages/weui-demos/demo.js

function jsonp158648493347411336(data){
  return data;
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    marginTop: wx.getSystemInfoSync()['statusBarHeight'] + 46,
    dialogShow: false,
    showOneButtonDialog: false,
    buttons: [{text: '取消'}, {text: '确定'}],
    oneButton: [{text: '确定'}],

  },

  openConfirm: function () {
    this.setData({
      dialogShow: true
    })
  },
  tapDialogButton(e) {
    this.setData({
      dialogShow: false,
      showOneButtonDialog: false
    })
  },
  tapOneDialogButton(e) {
    this.setData({
      showOneButtonDialog: true
    })
  },

  selectResult: function (e) {
    console.log('select result', e.detail)
  },
  search: function (value) {
    let fullurl = 'https://suggest.taobao.com/sug';
    let cookie = 'v=0; cookie2=16d477cca727399c4181e7f437190fe4; t=249a77726a4c40793aecc66515076363; _tb_token_=585eee8eab596; cna=5F/2Frcg6BcCAdoRxaz5Tt6T; _m_h5_tk=4ffb2259c99784dd02a0d40219f570a5_1586494936088; _m_h5_tk_enc=11b651c7ccf2c48ee7a230df4d32886d; isg=BIiIcRB_QiSoQK6gJFjIUZn-WfaaMew7wY0yL0I50IP2HSCH9kE1ywJbkfNtLaQT';
    let header = {
      "Content-Type": "text/html;charset=UTF-8",
    };
    header.cookie = cookie;
    return new Promise((resolve, reject) => {
      wx.request({
        url: fullurl,
        data: {
          q: value,
          code: 'utf-8',
          area: 'c2c',
          nick:'',
          sid: null,
          callback: 'jsonp158649923602291219'
        },
        header: header,
        success(res) {
          let cb_data = JSON.parse(res.data.substring(26,res.data.length-1)).result;
          let result = [];
          cb_data.forEach(item =>{
            result.push({
              text:item[0],
              value:item[1]
            })
          })
          resolve(result);
        },
        fail(res) {
          wx.showToast({
            title: 'wx.request fail',
            icon: 'none',
            duration: 1000,
            mask: true
          });
        }
      });
    })
  },
  searchInputFun(e){
    console.log(e.detail);
  },
  searchClearFun(){
    console.log('searchClearFun');
  },
  clearSearchInput(){
    console.log('clearSearchInput');
  },
  searchInputComfirm(e){
    /* 获取e.detail，就可以搜索了*/
    wx.showToast({
      title: e.detail
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      search: this.search.bind(this)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
